package com.wjyf.reducing_bento.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wjyf.reducing_bento.common.ErrorCode;
import com.wjyf.reducing_bento.exception.BusinessException;
import com.wjyf.reducing_bento.model.entity.Reward;
import com.wjyf.reducing_bento.service.RewardService;
import com.wjyf.reducing_bento.mapper.RewardMapper;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**
* @author 26439
* @description 针对表【tb_reward(佣金表)】的数据库操作Service实现
* @createDate 2023-04-29 19:15:02
*/
@Service
public class RewardServiceImpl extends ServiceImpl<RewardMapper, Reward>
    implements RewardService{

    @Override
    public Reward getRewardInfo() {
        Reward reward = this.list().get(0);
        return reward;
    }

    @Override
    public void setRewardInfo(BigDecimal amount) {
        if (amount == null || amount.doubleValue() < 0){
            throw new BusinessException(ErrorCode.PARAMS_ERROR, "设置金额必须大于等于0");
        }
        Reward reward = this.getRewardInfo()
                .setAmount(amount);
        boolean update = this.updateById(reward);
        if (!update){
            throw new BusinessException(ErrorCode.OPERATION_ERROR);
        }
    }

}




